package com.guan.ordering_sys.generator.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guan.ordering_sys.generator.entity.GoodsTypeParameter;
import com.guan.ordering_sys.generator.mapper.GoodsTypeParameterMapper;
import com.guan.ordering_sys.generator.service.GoodsTypeParameterService;
import com.guan.ordering_sys.vo.GoodsTypeParameterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 关远键
 * @since 2021-06-18
 */
@Service
public class GoodsTypeParameterServiceImpl extends ServiceImpl<GoodsTypeParameterMapper, GoodsTypeParameter> implements GoodsTypeParameterService {

    @Autowired
    private GoodsTypeParameterMapper goodsTypeParameterMapper;


    /**
     * 根据商品类型id获取所有参数
     * @param id
     * @return
     */
    @Override
    public GoodsTypeParameterVo getParamById(Long id) {
        GoodsTypeParameterVo parameterVo = new GoodsTypeParameterVo();
        List<JSONObject> jsObjects = new ArrayList<>();

        List<String> parameter = goodsTypeParameterMapper.getParameterById(id);
        for (String param : parameter){
            JSONObject jsonObject = JSONObject.parseObject(param);
            jsObjects.add(jsonObject);
        }

        parameterVo.setId(id);
        parameterVo.setValues(jsObjects);

        return  parameterVo;
    }



}
